﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Admin/Views/Shared/AdminMaster.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <legend>
        Danh sách học viên cần thu học phí
    </legend>

    <%
        //List<VietThuongLMS.HocVien_Lop> list = new List<VietThuongLMS.HocVien_Lop>();
        List < VietThuongLMS.HocVien_Lop > list = new List<VietThuongLMS.HocVien_Lop>();
        VietThuongLMS.LMSDataEntities Context = new VietThuongLMS.LMSDataEntities();
        list = Context.HocVien_Lop.Join(Context.LopHocs,
            hvl => hvl.MaLopHoc,
            lh => lh.ID,
            (hvl, lh) => hvl).Where(hvl => hvl.DongHocPhi == VietThuongLMS.Utils.Constant.HOCPHI_CHUADONG).Distinct().ToList();

        int maLop = 0;
        int countLop = 0;

        int maHocVien = 0;
        int countHocVien = 0;
        
        if (list != null && list.Count > 0)
        {
            countLop = 1;
            countHocVien = 1;
            maLop = int.Parse(list.ElementAt(0).MaLopHoc.ToString());
            maHocVien = int.Parse(list.ElementAt(0).MaHocVien.ToString());
            foreach (VietThuongLMS.HocVien_Lop hv in list)
            {
                //Count lop hoc
                if (maLop != hv.MaLopHoc)
                {
                    countLop++;
                }
                
                //Count hocvien
                if (maHocVien != hv.MaHocVien)
                {
                    countHocVien++;
                }
                                
                hv.LopHocReference.Load();
                hv.HocVienReference.Load();
                hv.HocVienReference.Value.TaiKhoanReference.Load();

            }
        }
    %>
    <p>Bạn có <%= countHocVien %> học viên cần thu học phí</p>
    <ul class="">
            <%
                if (list != null && list.Count() > 0)
                {
                    int i;
                    maHocVien = int.Parse(list.ElementAt(0).MaHocVien.ToString());
                    for (i = 0; i < list.Count(); i++)
                    {
                        if (maHocVien != list.ElementAt(i).MaHocVien)
                        {
                     %>
                        <li>
                            <a href="<%=ResolveUrl("~/Admin/HocVien/Detail/")%><%= list.ElementAt(i).MaHocVien %>">
                                <%=
                                    list.ElementAt(i).HocVienReference.Value.TaiKhoanReference.Value.HoTen
                                %>   
                            </a>
                        </li>
                    <% }
                    }
                    %>
                        <li>
                            <a href="<%=ResolveUrl("~/Admin/HocVien/Detail/")%><%= list.ElementAt(0).MaHocVien %>">
                                <%=
                                    list.ElementAt(0).HocVienReference.Value.TaiKhoanReference.Value.HoTen
                                %>   
                            </a>
                        </li>  
                    <%
                }                    
            %>
        </ul>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
</asp:Content>
